package com.lkd.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lkd.entity.Order;
import com.lkd.entity.Sku;
import com.lkd.mapper.OrderMapper;
import com.lkd.report.Collect;
import com.lkd.report.OrderCollect;
import com.lkd.result.R;
import com.lkd.service.OrderService;
import com.lkd.service.RegionService;
import com.lkd.service.SkuService;
import com.lkd.vo.SkuVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: Z.lx
 * @Date: 2025/8/22 21:00
 * @Description:
 **/
@RestController
@RequestMapping("/api/order-service/report")
@Slf4j
public class ReportController {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private RegionService regionService;
    @Autowired
    private SkuService skuService;
    @Autowired
    private OrderService orderService;

    @GetMapping("/orderCount")
    public String getOrderCount(String start, String end) {
        return orderMapper.orderCount(start, end);
    }

    @GetMapping("/orderAmount")
    public Double getOrderAmount(String start, String end) {
        Double v = orderMapper.sumPrice(start, end);
        return v == null ? 0 : (v*100);
    }

    @GetMapping("/amountCollect/{collectType}/{start}/{end}")
    public Map<String, Object> orderCollect(
            @PathVariable("collectType") Integer amountType,
            @PathVariable("start") String start,
            @PathVariable("end") String end) {
        return orderService.collect(amountType, start, end);
        /*Map<String, Object> data = new HashMap<>();

        List<String> xAxis = Arrays.asList("2024-01-01", "2024-01-02", "2024-01-03");
        List<Integer> series = Arrays.asList(1500, 2300, 1800);

        data.put("xAxis", xAxis);
        data.put("series", series);

        return data; // 直接返回data，不要外层包装*/
    }

    @GetMapping("/regionCollect/{start}/{end}")
    public Collect  regionCollect(@PathVariable("start") String start,
                                 @PathVariable("end") String end) {
        return regionService.regionCollect(start, end);

    }

    @GetMapping("/skuTop/{topValue}/{start}/{end}")
    public List<SkuVO> skuTop10(@PathVariable("topValue") String topValue,
                                @PathVariable("start") String start,
                                @PathVariable("end") String end) {
        return skuService.listTop10(topValue);
    }
}
